package com.nc.menu.controller;

import com.nc.menu.feign.OauthFeign;
import com.nc.menu.model.dto.MenuDto;
import com.nc.menu.service.MenuService;
import com.plug.result.RetResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * 创建人:    xvzhe
 * 创建时间:
 * 修改时间:
 * 版本:      v1.0
 */
@RestController
@RequestMapping("MenuController")
@Api
public class MenuController {
    @Autowired
    MenuService menuService;
    @Autowired
    HttpServletRequest request;
    @Autowired
    OauthFeign oauthFeign;

    @ApiOperation("新增菜单")
    @PostMapping("menu")
    public RetResult addMenu(@RequestBody MenuDto menuDto) {
        return menuService.save(menuDto);
    }

    @ApiOperation("更新菜单")
    @PutMapping("menu/{id}")
    public RetResult updateMenu(@PathVariable("id") String id, @RequestBody MenuDto menuDto) {
        menuDto.setId(id);
        return menuService.save(menuDto);
    }

    @ApiOperation("根据权限获得菜单")
    @PostMapping("menu/pers")
    public RetResult getPers(@RequestBody List<String> permissions) {
        return menuService.findByPermissions(permissions);
    }

    @ApiOperation("获得所有菜单-有层级")
    @GetMapping("menu/{userId}")
    public RetResult findAll(@PathVariable String userId){
        return menuService.findAll(userId);
    }

    @ApiOperation("获得所有菜单-无层级")
    @GetMapping("menu/all/no")
    public RetResult findNo(MenuDto menuDto){
        return menuService.findNo(menuDto);
    }
}
